/* Janus Chat - Version 1.0
 * Authors: Matthew Perry
 *          Michael Freid
 *          Marc Latou
 *          Richard Lee
 *
 * The Janus Chat Client is a highly secured
 * peer-to-peer chat client designed to facilitate
 * the transfer of sensitive data or as a communication
 * medium for the extra paranoid
 *
 * This file contains the implementation for the ConnectTab
 * QT class which allows the user to choose between server and
 * direct connections */

#include "connecttab.h"
#include "directtab.h"
#include "servertab.h"
#include "ui_connecttab.h"

/* The connectTab constructor:
 * Simple constructor which sets the UI
 * and connects the signals and slots for its
 * buttons */
ConnectTab::ConnectTab(User* user, QWidget *parent) :
    QWidget(parent),
    ui(new Ui::ConnectTab)
{
    //Initialize my User
    myUser = user;

    //Initialize all of the UI Elements (Widgets) for this class
    ui->setupUi(this);

    //Initialize the private variable myTabWidget to this class' parent
    myTabWidget = (QTabWidget*)parent;
    //Establish a signal and slot connection for the buttons on this class
    connect( ui->buttonDirect, SIGNAL(clicked()), this, SLOT(buttonDirect_clicked()) );
    connect( ui->buttonServer, SIGNAL(clicked()), this, SLOT(buttonServer_clicked()) );
}

/* Destructor */
ConnectTab::~ConnectTab()
{
    delete ui;
}

/* The Direct Button Slot:
 * Activated when the Direct Connect button
 * is clicked, this button spawns a new DirectTab
 * widget and removes the current tab */
void ConnectTab::buttonDirect_clicked()
{
    //Initialize a new DirectTab class
    DirectTab* dt = new DirectTab( myUser, myTabWidget );
    //Insert a new tab into the tabWidget using the DirectTab widget because the direct button was clicked
    int n = myTabWidget->insertTab( myTabWidget->currentIndex(), dt, "Direct Setup" );
    //Remove the old ConnectTab because we have moved on
    myTabWidget->removeTab( myTabWidget->currentIndex() );
    //Use slot to change the current tab index
    myTabWidget->setCurrentIndex( n );
}

/* The Server Button Slot:
 * Activated when the Server Connect button
 * is clicked, this button spawns a new ServerTab
 * widget and removes the current tab */
void ConnectTab::buttonServer_clicked()
{
    //Initialize a new ServerTab class
    ServerTab* st = new ServerTab( myUser, myTabWidget );
    //Insert a new tab into the tabWidget using the ServerTab widget because the server button was clicked
    int n = myTabWidget->insertTab( myTabWidget->currentIndex(), st, "Server Setup" );
    //Remove the old ConnectTab because we have moved on
    myTabWidget->removeTab( myTabWidget->currentIndex() );
    //Use slot to change the current tab index
    myTabWidget->setCurrentIndex( n );
}
